package qs.gwtmaven.sample.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;

public class Application implements EntryPoint {

    public void onModuleLoad() {
        final Label nameLabel = new Label("Name: ");
        final TextBox nameBox = new TextBox();
        final Label messageLabel = new Label("");
        final Button greetButton = new Button("Greet Me", new ClickHandler() {
            public void onClick(ClickEvent clickEvent) {
                GreetingsServiceAsync service=GWT.create(GreetingsService.class);
                service.greetMe(nameBox.getText(), new AsyncCallback<String>() {
                    public void onFailure(Throwable throwable) {
                        messageLabel.setText(throwable.getMessage());
                    }

                    public void onSuccess(String s) {
                        messageLabel.setText(s);
                    }
                });
            }
        });

        final HorizontalPanel rootPanel = new HorizontalPanel();
        rootPanel.add(nameLabel);
        rootPanel.add(nameBox);
        rootPanel.add(greetButton);
        rootPanel.add(messageLabel);

        RootPanel.get().add(rootPanel);
    }
}
